#include "StdAfx.h"
#include "MaterialDownloadEvent.h"
#include <shlwapi.h>
#pragma comment(lib,"shlwapi.lib")

CMaterialDownloadEvent::CMaterialDownloadEvent(void):m_hWndParent(NULL)
{
}

CMaterialDownloadEvent::~CMaterialDownloadEvent(void)
{
}

void CMaterialDownloadEvent::OnErrorCallBack(CStdString strTaskNo,DWORD dwCode, LPCTSTR lpError)
{
	if(m_hWndParent)
	{
		DOWNLOADERROR* pMsg = new DOWNLOADERROR;
		pMsg->strTaskNo = strTaskNo;
		pMsg->dwCode = dwCode;
		memset(pMsg->szError,0x0,MAX_PATH);
		_tcscpy(pMsg->szError,lpError);
		::PostMessage(m_hWndParent,WM_DOWNLOADPROGRESS_MESSAGE,0,(LPARAM)pMsg);
	}

}

void CMaterialDownloadEvent::OnProcessCallBack(CStdString strTaskNo,long long dwLength, long long dwTotalSize)
{
	if(m_hWndParent)
	{
		DOWNLOADPROGRESS* pMsg = new DOWNLOADPROGRESS;
		pMsg->strTaskNo = strTaskNo;
		pMsg->dwLength = dwLength;
		pMsg->dwTotalSize = dwTotalSize;
		::PostMessage(m_hWndParent,WM_DOWNLOADPROGRESS_MESSAGE,0,(LPARAM)pMsg);
	}
	
}

void CMaterialDownloadEvent::OnSetupCompleteCallBack(CStdString strTaskNo,BOOL bSuccessed)
{
	if(m_hWndParent)
	{
		SETUPCOMPLETE* pMsg = new SETUPCOMPLETE;
		pMsg->strTaskNo = strTaskNo;
		pMsg->bSuccessed = bSuccessed;
		::PostMessage(m_hWndParent,WM_SETUPCOMPLETE_MESSAGE,0,(LPARAM)pMsg);
	}
}

void CMaterialDownloadEvent::SetHwndParent(HWND hWnd)
{
	if(hWnd)
		m_hWndParent = hWnd;
}

void CMaterialDownloadEvent::OnDownloadComplete(CStdString strTaskNo,BOOL bSuccessed)
{
	if(m_hWndParent)
	{
		DOWNLOADCOMPLETE* pMsg = new DOWNLOADCOMPLETE;
		pMsg->strTaskNo = strTaskNo;
		pMsg->bSuccessed = bSuccessed;
		::PostMessage(m_hWndParent,WM_DOWNLOADCOMPLETE_MESSAGE,0,(LPARAM)pMsg);
	}
}
